package com.xr.oa.meeting;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.xr.common.CommUtil;

/**
 * roomViewModel
 */
public class roomViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
	Dataset ds=getDataset("datasetMeeting");
	DBStatement dbs = new DBStatement();
		RecordIterator ri = ds.recordIterator();
		ri.setVisibility(Dataset.FILTER_DELETED);
		while (ri.hasNext()) {
		  Record record = ri.nextRecord();
	     // dbs.setSql("update OA_MEETING set dr=1,dr_id="+CommUtil.getEmployeeId()+" where meeting_id="+record.getString("meeting_id"));
		  dbs.setSql("delete from OA_MEETING_COM where meeting_id="+record.getString("meeting_id"));
	      dbs.execute();
		}
		dbs.close();
    super.doUpdateData(parameters, outParameters);
  }
    public void updateCom(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {

		DBStatement dbs = new DBStatement();
		Dataset ds=getDataset("datasetMeetingCom");
		
		RecordIterator ri = ds.recordIterator();
		ri.setVisibility(Dataset.FILTER_ALL);
		while (ri.hasNext()) {
		  Record record = ri.nextRecord();
		  switch (record.getState()) {
		  case Record.STATE_NEW:
		    dbs.setSql("insert into OA_MEETING_COM(meeting_id, company_id, create_id, create_date)values("+ds.getString("meeting_id")+","+ds.getString("company_id")+","+CommUtil.getEmployeeId()+",sysdate)");
		    dbs.execute();
		    break;
		  case Record.STATE_MODIFIED:
			  dbs.setSql("update OA_MEETING_COM set company_id="+ds.getString("company_id")+" where meeting_id="+ds.getString("meeting_id")+" and company_id="+ds.getOldRecord(record).getString("company_id"));
			  dbs.execute();
		    break;
		  case Record.STATE_DELETED:
		    dbs.setSql("delete from OA_MEETING_COM where company_id="+ds.getString("company_id") +" and meeting_id="+ds.getString("meeting_id") );
		    dbs.execute();
		    break;
		  default:
		    
		}
		
		}
		dbs.close();
		
    //super.doUpdateData(parameters, outParameters);
  }


}
